package it.gma.torero.operator;

import it.gma.torero.operand.Operand;


/**
 * In logic and mathematics, a two-place logical operator and, also known as
 * <a href="http://en.wikipedia.org/wiki/Logical_conjunction">logical conjunction</a>, results in true if both of its operands are true,
 * otherwise the value of false. The analogue of conjunction for a (possibly
 * infinite) family of statements is universal quantification, which is part of
 * predicate logic.
 * 
 * 
 * @author giordano
 * 
 */
public class AndOperator extends AbstractBooleanOperator {


	public AndOperator(Operand operand1, Operand operand2) {
		super(operand1, operand2);
	}

	public boolean evaluate() {
		
		if (operand1.getValue() == null || operand2.getValue() == null) {
			throw new RuntimeException("Operands value cannot be null");
		}
		
		return ((Boolean)operand1.getValue()) && ((Boolean)operand2.getValue());
	}

	@Override
	public String toString() {
		return "(" + operand1 + " && " + operand2 + ")";
	}

}
